package com.sdruixinggroup.mondayb2b.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sdruixinggroup.mondayb2b.R;
import com.sdruixinggroup.mondayb2b.models.HomeBeen;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/12/10.
 */

public class HotHomeAdapter extends QuickAdapter<Object> {
    @BindView(R.id.iv_pic)
    ImageView ivPic;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_price)
    TextView tvPrice;

    private Context context;

    public HotHomeAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getLayoutID(int viewType) {
        if(viewType == HEADER_VIEW_TYPE){
            return R.layout.hot_title_layout;
        }
        return R.layout.home_hot_goods_view;
    }

    @Override
    public void convert(VH holder, Object itemData, int position) {
        ivPic =holder.getView(R.id.iv_pic);
        tvType =holder.getView(R.id.tv_type);
        tvName =holder.getView(R.id.tv_name);
        tvPrice = holder.getView(R.id.tv_price);
        if(itemData instanceof HomeBeen.HotBean){
            setData((HomeBeen.HotBean)itemData);
        }else if(itemData instanceof HomeBeen.RecommendBean){
            setData((HomeBeen.RecommendBean)itemData);
        }
    }

    @Override
    public int getItemViewType(int position) {
        Object data= getListData().get(position);
        if(data instanceof  Integer){
            return HEADER_VIEW_TYPE;
        }else {
            return CONTENT_VIEW_TYPE;
        }
    }

    private void setData(HomeBeen.RecommendBean hotBean) {
        Glide.with(context).load(hotBean.getThumb()).error(R.drawable.home_special_one).into(ivPic);
        if(1== hotBean.getType()){
            tvType.setVisibility(View.VISIBLE);
        }else {
            tvType.setVisibility(View.GONE);
        }
        tvName.setText(hotBean.getName());
        tvPrice.setText("¥ "+hotBean.getSale_price());
    }

    private void setData(HomeBeen.HotBean hotBean) {
        Glide.with(context).load(hotBean.getThumb()).error(R.drawable.home_special_one).into(ivPic);
        if(1== hotBean.getType()){
            tvType.setVisibility(View.VISIBLE);
        }else {
            tvType.setVisibility(View.GONE);
        }
        tvName.setText(hotBean.getName());
        tvPrice.setText("¥ "+hotBean.getSale_price());
    }


}
